package drt.toolbox.screen;

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

public class Screen {
	private int destkopWidth;
	private int destkopHeight;
	private Robot robot;
	private BufferedImage preparedImage;
	
	public Screen(){
		try {
			Robot robot = new Robot();
			destkopWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
			destkopHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}
	
	public int getWidth(){
		return destkopWidth;
	}
	
	public int getHeight(){
		return destkopHeight;
	}

	public BufferedImage prepare(){
		preparedImage = robot.createScreenCapture(new Rectangle(0,0,destkopWidth,destkopHeight));
		return preparedImage;
	}
	
	public boolean prepareCompare(Pixel pixel){
		prepare();
		return compare(pixel);
	}
	
	public boolean compare(Pixel pixel){
		Pixel other = new Pixel(pixel.x,pixel.y,preparedImage);
		if (other.equals(pixel))
			return true;
		return false;
	}
	
	public boolean prepareCompare(Checksum checksum){
		prepare();
		return compare(checksum);
	}
	
	public boolean compare(Checksum checksum){
		Checksum other = new Checksum(checksum.aX,checksum.aY,checksum.bX,checksum.bY, preparedImage);
		if (other.equals(checksum))
			return true;
		return false;
	}
	
	public Pixel search(Pixel pixel){
		prepare();
		for (int i = 0; i < preparedImage.getWidth(); i++){
			for (int j = 0; j < preparedImage.getHeight(); j++){
				if (new Pixel(i,j,preparedImage).equals(pixel)){
					return new Pixel(i, j, preparedImage);
				}
			}
		}
		return null;
	}

}
